package com.yanqu.road.server.manager.activity.snowgarden;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.snowgarden.config.SnowGardenBuyConfig;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.logic.bussiness.servercenter.ActivityBussiness;
import com.yanqu.road.server.CrossBaseServer;
import com.yanqu.road.server.TempCrossMgr;
import com.yanqu.road.utils.date.DateHelper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CrossActivityMallDayBuyConfigMgr extends TempCrossMgr {
    private static Map<Integer, SnowGardenFakeBuyConfig> snowGardenFakeBuyConfigMap = new HashMap<>();

    @Override
    public boolean removeExpireData() throws Exception {
        return true;
    }

    @Override
    public boolean init() throws Exception {
        return reload();
    }

    @Override
    public boolean reloadConfig() throws Exception {
        reloadBuyConfig();
        return true;
    }

    @Override
    public boolean reloadData() throws Exception {
        return true;
    }

    @Override
    public boolean stop() {
        return true;
    }

    public static synchronized void reloadBuyConfig() {
        getLogger().info("reload  CrossActivityMallDayBuyConfigMgr start");
        String nowTimeStr = DateHelper.getCurrentDateTimeString();
        List<Integer> activityTypeList = new ArrayList<>();
        activityTypeList.add(eActivityType.SnowGarden.getValue());
        activityTypeList.add(eActivityType.SummerGames.getValue());
        if (activityTypeList.isEmpty()) {
            snowGardenFakeBuyConfigMap = new HashMap<>();
            return;
        }

        Map<Integer, ActivityInfo> activityInfoMap = ActivityBussiness.getOpenCrossRankActivityInfoMapByCrossServerId(activityTypeList, nowTimeStr, CrossBaseServer.getInstance().getServerId());
        for (ActivityInfo item : activityInfoMap.values()) {
            reloadConfig(item);
        }
        getLogger().info("reload CrossActivityMallDayBuyConfigMgr end");
    }

    public static SnowGardenFakeBuyConfig reloadConfig(ActivityInfo activityInfo) {
        SnowGardenFakeBuyConfig snowGardenFakeBuyConfig = new SnowGardenFakeBuyConfig(activityInfo);
        snowGardenFakeBuyConfigMap.put(activityInfo.getActivityId(), snowGardenFakeBuyConfig);
        return snowGardenFakeBuyConfig;
    }

    public static SnowGardenFakeBuyConfig getSnowGardenFakeBuyConfig(int activityId) {
        return snowGardenFakeBuyConfigMap.get(activityId);
    }
}
